<template>
  <div class="container">
    <el-row class="table-top">
      <div class="left">
        <el-button v-permission="['84002']" type="primary" @click="openFrom"> 添加服务报价 </el-button>
      </div>
    </el-row>

    <el-table :data="tableData" style="width: 100%" :header-cell-style="{background:'#F7F8FA'}">
      <el-table-column prop="project_category_code" align="center" label="项目编码" />
      <el-table-column prop="service_category_desc" align="center" label="描述" />
      <el-table-column prop="main_service_quotation" align="center" label="主服务报价" />
      <el-table-column prop="sub_service_quotation" align="center" label="次服务报价" />
      <el-table-column align="center" label="操作" width="120">
        <template slot-scope="scope">
          <el-button v-permission="['84003']" type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button v-permission="['84004']" type="text" size="small" @click="handleDeleta(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="broadfun_block">
      <el-pagination
        :current-page="seachValue.pagenum"
        :page-sizes="[10, 20, 50]"
        :page-size="seachValue.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>

    <ServiceFrom :id="editId" ref="LevelFrom" :visible="visible" :form="editFrom" @close="closeFum" @success="successFun" />
  </div>
</template>

<script>
import ServiceFrom from './components/ServiceFrom'
import { projectCategoryList, delProjectCategory } from '@/api/base'
export default {
  name: 'ServiceOffer',
  components: {
    ServiceFrom
  },
  data() {
    return {
      tableData: [],
      editId: 0,
      editFrom: {},
      visible: false,
      total: 0,
      seachValue: {
        pagenum: 1,
        pagesize: 10
      }
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    async init() {
      const res = await projectCategoryList(this.seachValue)
      if (res.ret === 0) {
        this.tableData = res.data.list
        this.total = res.data.total
      } else {
        this.tableData = []
        this.total = 0
      }
    },
    openFrom() {
      this.editId = 0
      this.visible = true
    },
    async handleDeleta(row) {
      const isDelete = await this.$confirm(`确定删除${row.project_category_code}`, '提示', { type: 'warning' })
      if (!isDelete) {
        return
      }
      const res = await delProjectCategory(row.ID)
      if (res.ret === 0) {
        this.$message.success('删除成功')
        this.init()
      }
    },
    handleEdit(row) {
      this.editId = row.ID
      this.editFrom = JSON.parse(JSON.stringify(row))
      this.visible = true
    },
    handleSizeChange(val) {
      this.seachValue.pagenum = 1
      this.seachValue.pagesize = val
      this.init()
    },
    handleCurrentChange(val) {
      this.seachValue.pagenum = val
      this.init()
    },
    closeFum() {
      this.visible = false
    },
    successFun() {
      this.visible = false
      this.init()
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding-bottom: 50px;
}
</style>
